package examples;
import java.awt.Graphics2D;
import java.awt.Shape;

import prefuse.render.AbstractShapeRenderer;
import prefuse.render.LabelRenderer;
import prefuse.render.ShapeRenderer;
import prefuse.visual.VisualItem;

public class LabelShapeRenderer extends AbstractShapeRenderer {

  private ShapeRenderer m_shapeRenderer;
  private LabelRenderer m_labelRenderer;

  public LabelShapeRenderer() {
    m_shapeRenderer = new ShapeRenderer();
    m_labelRenderer = new LabelRenderer();
    m_labelRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_NONE);
  }

  public LabelShapeRenderer(String textField, int size) {
    m_shapeRenderer = new ShapeRenderer(size);
    m_labelRenderer = new LabelRenderer(textField);
    m_labelRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_NONE);
  }

  @Override
  public void render(Graphics2D g, VisualItem item) {
    m_shapeRenderer.render(g, item);
    m_labelRenderer.render(g, item);
  }

  @Override
  // /XXX getRawShape should return the "raw", not transformed shape!
  // Actually, it just returns the (already transformed) ShapeRenderers shape.
  protected Shape getRawShape(VisualItem item) {
    return m_shapeRenderer.getShape(item);
  }

}